package com.lx.pc.service.supplydemand.impl;

import java.math.BigInteger;
import java.util.List;

import org.springframework.stereotype.Service;

import com.lx.pc.domain.entity.supplydemand.SupplydemandEntity;
import com.lx.pc.domain.vo.supplydemand.SupplydemandVo;
import com.lx.pc.mybatis.repository.supplydemand.SupplydemandRepository;
import com.lx.pc.service.AbstractService;
import com.lx.pc.service.supplydemand.ISupplydemandService;
import com.lx.pc.utils.OmsPage;

@Service("supplydemandService")
public class SupplydemandServiceImpl extends AbstractService<SupplydemandEntity, SupplydemandVo, BigInteger, SupplydemandRepository> implements ISupplydemandService{

	@Override
	public int findBySupplydemandCount(SupplydemandVo supplydemand) {

		return repository.findBySupplydemandCount(supplydemand);
	}

	@Override
	public OmsPage<SupplydemandVo> findBySupplydemand(SupplydemandVo supplydemand, Integer page, Integer size) {

		OmsPage<SupplydemandVo> pages = new OmsPage<SupplydemandVo>();
		pages.setTotal(repository.findBySupplydemandCount(supplydemand));
		List<SupplydemandEntity> list = repository.findBySupplydemand(supplydemand,page = (page - 1) * size,size);
		pages.setResult(etoV(list));
		return pages;
	}

	@Override
	public SupplydemandVo findBySupplydemandId(BigInteger id) {
		
		return etoV(repository.findBySupplydemandId(id));
	}

	@Override
	public OmsPage<SupplydemandVo> findByWxSupplydemand(SupplydemandVo supplydemand, Integer page, Integer size) {
		
		OmsPage<SupplydemandVo> pages = new OmsPage<SupplydemandVo>();
		pages.setTotal(repository.findByWxSupplydemandCount(supplydemand));
		List<SupplydemandEntity> list = repository.findByWxSupplydemand(supplydemand,page = (page - 1) * size,size);
		pages.setResult(etoV(list));
		return pages;
	}

	@Override
	public SupplydemandVo findByWxSupplydemandId(BigInteger id) {

		return etoV(repository.findByWxSupplydemandId(id));
	}

	@Override
	public String updateSupplydemand(SupplydemandVo supplydemand) {

		repository.update(supplydemand);
		return supplydemand.getId().toString();
	}

}
